/***************************
统计分析-部门汇总
* */
<template>
  <basic-container>
    <div class="boxsty zhiBiao" v-if="zhiShow == 1">
      <el-row>
        <assessMentHead :sign="{ a: true, b: false, c: false,d: false,e: false}" ></assessMentHead>
      </el-row>
      <el-row style="margin:25px 0 0 0 ;">

        <div :height="searchheight">
        <span style="float:right;margin-top: -30px;cursor: pointer;" @click="searchchangeadvanced">
          {{ searchadvanced ? "查询条件收起" : "查询条件展开" }}
          <i
            :class="searchadvanced ? 'el-icon-arrow-up' : 'el-icon-arrow-down'"
          />
        </span>
          <div v-show="searchadvanced">
            <el-form :inline="true" :model="searchForm" class="form-inline">

              <el-form-item label="统计名称">
                <!-- <el-input v-model="searchForm.tjmc" placeholder="统计名称" :clearable="true"></el-input>-->
                <selectSearch @getDataByTjmc="getDataByTjmc"></selectSearch>
              </el-form-item>

              <!--   <el-form-item label="状态">
                   <el-select
                     v-model="searchForm.state"
                     placeholder="请选择状态"
                     class="xiaLa"
                     style="width: 100%"
                     :clearable="true"
                   >
                     <el-option
                       v-for="(item, index) in statesList"
                       :key="index"
                       :label="item.name"
                       :value="item.value"
                     ></el-option>
                   </el-select>
                 </el-form-item>-->
              <el-form-item>
                <el-button
                  icon="el-icon-search"
                  type="primary"
                  class="marginLeft"
                  @click="getDataList(1)"
                >检索</el-button>
              </el-form-item>
            </el-form>
          </div>
        </div>
      </el-row>
      <el-row>
        <div style="height: 50px; border-bottom: 1px solid #b0bde2">
<!--          <el-tooltip
            class="item"
            effect="dark"
            :content="contentName"
            placement="top"
          >
            <el-button
              icon="el-icon-plus"
              type="primary"
              circle
              @click="addOrEdit()"
            ></el-button>
          </el-tooltip>
          <el-tooltip
            class="item"
            effect="dark"
            content="批量删除选中的数据"
            placement="top"
          >
            <el-button
              type="danger"
              icon="el-icon-delete"
              :disabled="canDelete"
              @click="deleteBatch()"
              circle
            ></el-button>
          </el-tooltip>-->
          <div class="pull-right">
<!--            <el-button plain type="primary"  :disabled="canSubmit" @click="ldsh">领导审核</el-button>-->
            <el-button plain type="primary" @click="download">导出</el-button>

          </div>
        </div>

      </el-row>
      <el-row>
        <el-table
          style="width: 100%;margin-top:20px"
          :data="dataList"
          border
          stripe
          header-align="center"
          ref="tableRef"
          v-if="rednermsg"
          v-loading="dataListLoading"
          @selection-change="handleSelectionChange"
        >
          <el-table-column type="selection" width="55"></el-table-column>
          <el-table-column type="index" :index="indexMethod"  header-align="center" align="center" label="序号" width="55"></el-table-column>
          <el-table-column prop="hzzqmc" align="center" label="统计名称" show-overflow-tooltip ></el-table-column>
          <el-table-column prop="bz" align="center" label="备注" show-overflow-tooltip></el-table-column>
          <el-table-column prop="createTime" align="center" min-width="120" label="创建时间"  show-overflow-tooltip></el-table-column>
          <el-table-column prop="state" align="center" min-width="100" label="状态"  show-overflow-tooltip>
            <!-- <template slot-scope="scope">
               <span>{{scope.row.state |transState}}</span>
             </template>-->
            <template slot-scope="scope">
              <div>
                <el-popover placement="top" width="660" trigger="hover">
                  <el-table :data="scope.row.gridData" max-height="400">
                    <el-table-column
                      width="260"
                      property="NAME_"
                      label="任务名称"
                      show-overflow-tooltip
                    ></el-table-column>
                    <el-table-column
                      width="120"
                      property="ry_name"
                      label="处理人"
                      show-overflow-tooltip
                    ></el-table-column>
                    <el-table-column
                      width="120"
                      property="START_TIME_"
                      label="开始时间"
                      show-overflow-tooltip
                    ></el-table-column>
                    <el-table-column
                      width="120"
                      property="END_TIME_"
                      label="结束时间"
                      show-overflow-tooltip
                    ></el-table-column>
                  </el-table>
                  <span slot="reference">{{scope.row.state |transState}}</span>
                  <el-button
                    type="primary"
                    icon="el-icon-search"
                    @click="showMessage(scope.row.proceId,scope.row)"
                  >流程跟踪</el-button>
                </el-popover>
              </div>
            </template>
          </el-table-column>
          <el-table-column align="center" width="240" fixed="right" label="操作">

            <template slot-scope="scope">
<!--              <el-button
                type="primary"
                plain
                size="small"
                @click="scoreCollect(scope.row)"
              >分数汇总</el-button>-->

              <el-button
                type="primary"
                plain
                size="small"
                @click="scoreLevel(scope.row)"
              >评分查看</el-button>
            </template>
          </el-table-column>
        </el-table>
        <!--分页-->
        <div class="avue-crud__pagination">
          <el-pagination
            @size-change="sizeChangeHandle"
            @current-change="currentChangeHandle"
            :current-page="pageIndex"
            :page-sizes="[10, 20, 50, 100]"
            :page-size="pageSize"
            :total="totalPage"
            background
            layout="total, sizes, prev, pager, next, jumper"
          ></el-pagination>
        </div>

      </el-row>

    </div>

    <!-- 评分等级" -->
    <scoreLe
      @refreshDataList="getDataList()"
      v-if="zhiShow == 3"
      v-on:fnBackOldPage="fnBackOldPage"
      ref="level"
      @closeDialog="closeDialog"
    />
    <!-- 分数汇总 v-if="shzVisible" -->


    <processTracking
      ref="processTracking"
      @processTrackingChildren="getDataList"
    ></processTracking>

  </basic-container>
</template>

<script>
import assessMentHead from "@/views/statisticsanalysis/components/assessMentHead"; //转态头
import selectSearch from "@/views/statisticsanalysis/components/selectSearch";
import processTracking from "@/views/statisticsanalysis/components/processTracking";
import scoreLe from "./scoreLe"; //组件


// 接口 api
import {
  pfhzbmhzList,
  isAllScore,
  isAllPfdj,
  exportExcel,
  deleteZbmhz, pfhzsearchList,
} from "@/api/statisticsanalysis/pfhzbmhzApi.js";
export default {
  data() {
    return {
      canDelete :true,
      canSubmit: true,
      chooseVisible:false,
      customDialogData: {},
      addVisible: false, //新增or编辑弹窗显隐
      shzVisible: false,
      searchheight: "0", //搜索组件的高度
      searchadvanced: true, //搜索的显隐
      contentName : '新增',
      searchForm: {}, //查询表单
      multipleSelection: [], //表格中被选中的数据
      dataList: [],
      dataListLoading: false,
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      rednermsg: true,
      statesList : [
        { name: "待审核", value: "0" },
        { name: "已审核", value: "1" },
        { name: "驳回", value: "2" },
      ],
      zhiShow: "1",
    }
  },
  filters: {
    transState(val) {
      switch (val) {
        case '0':
          return "待审核";
          break;
        case '1':
          return "审核中";
          break;
        case '2':
          return "已审核";
          break;
        case '3':
          return "已驳回";
          break;

      }
    }
  },
  components: {
    assessMentHead, //状态头
    selectSearch,//下拉选搜索组件
    scoreLe,
    processTracking
  },
  created() {
    this.getDataList();

  },
  methods: {
    //选择统计名称执行搜索功能
    getDataByTjmc(tjmc){
      this.searchForm.hzzqmc = tjmc ;
      this.getDataList() ;
    },
    // 显示信息
    showMessage(proId,row) {
      //console.log(row);
      this.$refs.processTracking.init(proId);
    },

    // 自定义流程
    customBtn() {
      this.chooseVisible = false;
      this.customDialogData = {
        dialogVisible: true,
        type: 2,
        iszbsh: 1,
        rows: this.$refs.tableRef.selection,
        menuType: "zbnd"
      };
    },
    customDialogChildren(data) {
      this.getDataList();
    },
    // 查询条件的展开关闭
    searchchangeadvanced() {
      this.searchadvanced = !this.searchadvanced;
      if (this.searchadvanced) {
        this.searchheight = "auto";
      }
    },
    // 勾选数据
    handleSelectionChange(val) {
      let isSubmit = val.every(it => {
        return it.state == 0 || it.state == 3;
      });
      let isDelete = val.every(it => {
        return it.state == 0 || it.state == 3;
      });
      if (val.length == 0) {
        this.canSubmit = true;
        this.canDelete = true;
      } else {

        if (isSubmit) {
          this.canSubmit = false;
        } else {
          this.canSubmit = true;
        }

        if (isDelete) {
          this.canDelete = false;
        } else {
          this.canDelete = true;
        }
      }


      this.multipleSelection = val;
    },
    // 新增或者编辑
    addOrEdit(data) {
      this.addVisible = true;
      if (data) {
        this.$nextTick(() => {
          this.$refs.addNode.init(data);
        });
      } else {
        this.$nextTick(() => {
          this.$refs.addNode.init();
        });
      }
    },
    //删除数据
    deleteBatch(){
      this.$confirm("此操作将删除选中的数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          let ids = this.multipleSelection.map(it => {
            return it.id;
          });
          deleteZbmhz(ids.toString()).then(r => {
            if (r.data.code == 0) {
              this.$message.success("删除成功");
              this.getDataList();
            } else {
              this.$message.error(r.data.msg);
              this.getDataList();
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },
    scoreCollect(data){
      this.zhiShow = 2;
      if (data) {
        this.$nextTick(() => {
          this.$refs.shz.init(data);
        });
      }

    },
    async scoreLevel(data){
      const  scoreFalg = await  isAllScore(data.id) .then(res => {return res.data.data});
      console.log(scoreFalg)
      if(scoreFalg){
        this.zhiShow = 3;
        if (data) {
          this.$nextTick(() => {
            this.$refs.level.init(data);
          });
        }
      }else{
        this.$message.warning("所有综合得分不为空");
        return false;
      }
    },
    download(){
      const rows = this.$refs.tableRef.selection;
      if (rows.length == 0) {
        this.$message.closeAll();
        this.$message({
          type: "info",
          message: "请至少选择一条数据提交!"
        });
        return false;
      }else {
        if(rows.length == 1){
          let ids = this.$refs.tableRef.selection.map(it => {
            return it.id;
          });
          const filename = "导出" + ".xlsx";
          exportExcel(
            Object.assign(
              {
                ids: ids.toString()
              }
            )
          ).then((response) => {
            this.$message.closeAll();
            this.$message.success("导出成功!");
            let url = window.URL.createObjectURL(new Blob([response.data]));
            let link = document.createElement("a");
            link.style.display = "none";
            link.href = url;
            link.setAttribute("download", filename);
            document.body.appendChild(link);
            link.click();
          });
        }else{
          this.$message.closeAll();
          this.$message({
            type: "info",
            message: "至多只能选择一条数据提交!"
          });
          return false;
        }

      }
    },
    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val
      this.pageIndex = 1
      this.getDataList()
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val
      this.getDataList()
    },
    // 获取数据列表
    getDataList() {
      this.dataListLoading = true;

      pfhzsearchList(
        Object.assign(
          {
            current: this.pageIndex, //当前页
            size: this.pageSize, // 每页条数
          },
          this.searchForm,
        )
      )
        .then(response => {
          this.dataList = response.data.data.records;
          this.totalPage = response.data.data.total;
          this.dataListLoading = false;
        })
        .catch(() => {
          this.dataListLoading = false;
        });
    },
    ldsh(){
      const rows = this.$refs.tableRef.selection;
      if (rows.length == 0) {
        this.$message.closeAll();
        this.$message({
          type: "info",
          message: "请至少选择一条数据提交!"
        });
        return false;
      }else{
        let ids = this.multipleSelection.map(it => {
          return it.id;
        });

        isAllPfdj(ids.toString()).then(response => {
          console.log(response.data.data)
          if (response.data.data) {
            this.chooseVisible = false;
            this.customDialogData = {
              dialogVisible: true,
              type: 2,
              iszbsh: 1,
              rows: this.$refs.tableRef.selection,
              menuType: "zbnd"
            };
          } else {
            this.$message.closeAll();
            this.$message({
              type: "error",
              message: "当前数据的评分等级未全选择！"
            });
          }
        });
      }
    },
    //子集信息
    fnBackOldPage(data) {
      if (data == "返回原页面") {
        this.zhiShow = 1;
        this.getDataList();
      }
    },
    indexMethod(index) { //修改table表索引

      return (this.pageIndex-1)*this.pageSize+index+1;
    },
    // 关闭新增or编辑弹窗
    closeDialog() {
      this.addVisible = false;
      this.getDataList();
    }
  }
}
</script>

<style scoped>

</style>
